@extends('default.layouts.adminPublic')
@section('title', '用户列表')

@section('content')
<!--导航开始-->
<div class="crumb_warp">
    <i class="fa fa-home"></i> <a href="{{url('admin')}}">首页</a> &raquo; 用户管理
</div>
<!--导航结束-->

<!--搜索结果页面 列表开始-->
<form action="#" method="post">
    <div class="result_wrap">
        <div class="result_title">
            <h3>用户列表</h3>
            @if(count($errors)>0)
                <div class="mark">
                    @if(is_object($errors))
                        @foreach($errors->all() as $error)
                            <p>{{$error}}</p>
                        @endforeach
                    @else
                        <p>{{$errors}}</p>
                    @endif
                </div>
            @endif
            @include('flash::message')
        </div>
        <!--快捷导航 开始-->
        <div class="result_content">
            <div class="short_wrap">
                <a href="{{url('admin/admin_user/create')}}"><i class="fa fa-plus"></i>添加用户</a>
                <a href="{{url('admin/admin_user')}}"><i class="fa fa-recycle"></i>用户列表</a>
            </div>
        </div>
        <!--快捷导航 结束-->
    </div>

    <div class="result_wrap">
        <div class="result_content">
            <table class="list_tab">
                <tr>
                    <th width="20%">用户名称</th>
                    <th width="30%">用户邮箱</th>
                    <th>所属角色</th>
                    <th width="15%">操作</th>
                </tr>
                @if(count($userRoleArr)>0)
                    @foreach($userRoleArr as $v)
                        <tr>
                            <td>{{$v->name}}</td>
                            <td>{{$v->email}}</td>
                            @if($v->is_super)
                                <td><strong style="font-size: 16px">超级管理员</strong></td>
                            @else
                                <td>
                                    @foreach($v->roles as $vv)
                                        <strong style="font-size: 15px; color: #777; margin-right:15px;">{{$vv->display_name}}</strong>
                                    @endforeach
                                </td>
                            @endif
                            <td>
                                <a href="{{url('admin/admin_user/'.$v->id.'/edit')}}">修改</a>
                                <a  onclick="delUser({{$v->id}})">删除</a>
                            </td>
                        </tr>
                    @endforeach
                @endif
            </table>
            <div class="page_list" style="width: 100%">
                {!! $users->links() !!}
            </div>

        </div>
    </div>
</form>
<!--搜索结果页面 列表结束-->

<script>
    //删除用户
    function delUser(role_id) {
        layer.confirm('您确定要删除这个用户吗？', {
            btn: ['确定', '取消'] //按钮
        }, function () {
            $.post("{{url('admin/admin_user/')}}/" + role_id, {
                '_method': 'delete',
                '_token': "{{csrf_token()}}"
            }, function (data) {
                if (data.status == 0) {
                    location.href = location.href;
                    layer.msg(data.msg, {icon: 6});
                } else {
                    layer.msg(data.msg, {icon: 5});
                }
            });
        }, function () {

        });
    }
</script>
@endsection